package de.geckocraft.iConomyExchange.mysql;

import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;

import de.geckocraft.iConomyExchange.main.main;




public class mysqlconfig
{
	private static File					file;
	private static FileConfiguration	config;
	
	public static void loadConfig()
	{

		Plugin mainplugin = main.plugin;
		String filename = "mysql.yaml";
		file = new File(mainplugin.getDataFolder().getAbsolutePath(), filename);

		if (!file.exists())
		{
			try
			{
				file.getParentFile().mkdirs();
				file.createNewFile();
			} catch (IOException e)
			{
				file = null;
				return;
			}

			System.out.println(filename + " erstellt");
		}

		try
		{
			config = YamlConfiguration.loadConfiguration(file);
			config.options().copyDefaults(true);
		} catch (Exception e)
		{
			e.printStackTrace();
		}
		createDefaultConfig();
		broker.connect();
	}
	
	public static void createDefaultConfig()
	{
		config.addDefault("ip", "127.0.0.1");
		config.addDefault("port", "8889");
		config.addDefault("database", "minecraft");
		config.addDefault("user", "root");
		config.addDefault("password", "root");
		save();
	}
	
	protected static void save()
	{
		try
		{
			config.save(file);
		} catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static FileConfiguration	getconfig()
	{
		return config;
	}
}
